package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"protobuf/pb"
)

func main() {
	// 1. 连接grpc服务
	grpcConn, err := grpc.Dial("127.0.0.1:8080", grpc.WithInsecure())
	if err != nil {
		fmt.Println("grpc.Dial err: ", err)
		return
	}
	defer grpcConn.Close()

	// 2. 初始化grpc客户端
	grpcClient := pb.NewSayNameClient(grpcConn)

	//创建并初始化Teacher对象
	var teacher pb.Teacher
	teacher.Name = "MrTony"
	teacher.Age = 18

	// 3. 调用远程服务
	t, err := grpcClient.SayHello(context.TODO(), &teacher)
	fmt.Println(t, err)
}
